
//
//  UIViewExtension.swift
//  HuaDaoPeifu
//
//  Created by Erickson on 16/4/7.
//  Copyright © 2016年 paiyipai. All rights reserved.
//

extension UIView {
    func config<T>(_ callback: (T) -> Void) {
        callback(self as! T)
    }
}


extension UITabBar {
    func showBadgeValueAtItemIndex(_ index:Int) {
        hiddenBadgeValueAtItemIndex(index)
        let badgeView = UIView()
        badgeView.tag = 20160511 + index
        badgeView.backgroundColor = UIColor.red
        let tabFrame = self.frame
        
        let percentX:Float = (Float(index) + 0.6 ) / 3
        let x = ceilf(percentX * Float(tabFrame.size.width))
        let y = ceilf(0.1 * Float(tabFrame.size.height))
        badgeView.frame = CGRect(x: CGFloat(x), y: CGFloat(y), width: 10, height: 10)
        badgeView.layer.cornerRadius = badgeView.frame.size.width*0.5
        self.addSubview(badgeView)

    }
    
    func hiddenBadgeValueAtItemIndex(_ index:Int) {
        for subView in self.subviews {
            if subView.tag == 20160511 + index {
                subView.removeFromSuperview()
            }
        }
    }
}


//protocol HDBackBarButtonItemAble {
//    func setBackBarButtonItem()
//}
//
//extension HDBackBarButtonItemAble where Self : UIViewController {
//    
//    func setBackBarButtonItem() {
//        navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
//        
//    }
//    
//}
